<?php
class TvbDamsDistributor extends BaseDistributor {
	const DAMS_BASE = 'rtmpe://streaming.tvb.com/dams';
	
	public function getDestinationId() {
		return 0;
	}

	public function distribute(array $data) {
		return TRUE;
	}
	
	public function getVideo($export_id) {
		$rf = VideoInfrastructure::GetReadableRecordFactory();
		
		$export_entry = $rf->findInstance('Export', $export_id);

		if (!$export_entry) {
			return -2;	// Export video not found
		}
				
		if ($export_entry->ready != 1) {
			return $export_entry->ready; // Video is not ready
		}
		
		$file = VideoInfrastructure::GetExportedStorage($export_id, $export_entry->farm, $export_entry->format_id);
		$file_path = str_replace('/data/video_infrastructure/video/', '', $file);
		
		return array(
			'app_url' => self::DAMS_BASE,
			'file' => "mp4:{$file_path}",
		);
	}
	
	public function getVideoListBySourceId($source_id) {
	}
}

$distributor = new TvbDamsDistributor();
$ret = DistributorFactory::getInstance()->register($distributor->getDestinationId(), $distributor);
?>
